package com.crealth.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;


public class ReadWriteFile {
	private static String fileName = "validPhoneCode.txt";
	
    public static void writeLog(String str) {
        try {	        
	        File file = new File(fileName);
	        if(!file.exists()) {
	            file.createNewFile();
	        }
	        
	        FileOutputStream out = new FileOutputStream(file, true);
	        
	        out.write(str.getBytes("utf-8"));
	        out.close();
        }
        catch(IOException ex) {
            System.out.println(ex.getStackTrace());
        }
    }
    
    public static String readLog() {
        StringBuffer sb = new StringBuffer();
        String tempstr = null;
        try {            
            File file=new File(fileName);
            FileInputStream fis = new FileInputStream(file);
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            while((tempstr = br.readLine()) != null) {
                sb.append(tempstr);
            }
            br.close();
        }
        catch(IOException ex) {
            System.out.println(ex.getStackTrace());
        }
        return sb.toString();
    }
    
    
}
